//
//  RSSwapButton.m
//  StaffTax
//
//  Created by 侯伟 on 2020/1/3.
//  Copyright © 2020 侯伟. All rights reserved.
//

#import "RSSwapButton.h"

@implementation RSSwapButton

- (void)layoutSubviews{
    [super layoutSubviews];
    
    UIImageView* imageView = self.imageView;

    UILabel* titleLb = self.titleLabel;
    if(!imageView || !titleLb)
        return;
    
    CGFloat max = MAX(imageView.rs_width, imageView.rs_height);
    imageView.rs_width = max;
    imageView.rs_height = max;
    
    CGFloat marginLeft = (self.frame.size.width - imageView.frame.size.width - titleLb.frame.size.width - self.gap)/2;
    
    CGRect titleFrame = titleLb.frame;
    titleFrame.origin.x = marginLeft;
    titleLb.frame = titleFrame;
    titleLb.textAlignment = NSTextAlignmentRight;
    
    CGRect imageFrame = self.imageView.frame;
    imageFrame.origin.x = marginLeft + self.gap + self.titleLabel.frame.size.width;
    imageView.frame = imageFrame;
}

@end
